using System;
using System.Collections.Generic;
using System.Text;
using Musicman.Entities.BusinessEntities;
using System.Globalization;

namespace Musicman.Entities
{
	public class Searchjob
	{
		private long? searchjobid;
		private string name;
		private string allcriteria;
		private byte? type;
        private DateTime? starttime;
        private DateTime? endtime;
        private long? totalfiles;
        private long? totalLength;
        private float gbLength = 0;
        private SearchFileCollection files;
        private SearchLocationCollection searchlocations;
        private CultureInfo MyCi = new CultureInfo("en-US");

        public void AddSearchLocation(Searchlocation location)
        {
            searchlocations.Add(location);
        }

        public void AddSearchFile(Searchfile file)
        {
            Searchlocation slOld;
            Searchlocation sl = file.Folder.SearchLocation;
            if (this.searchlocations.Contains(sl))
            {
                slOld = searchlocations[sl.Name];
                slOld.CopyProperties(sl);
            }
            else
            {
                slOld = new Searchlocation();
                slOld.Searchjobid = this.searchjobid;
                slOld.CopyProperties(sl);
                this.searchlocations.Add(slOld);
            }
            slOld.AddSearchFile(file);
        }

		public long? Searchjobid
		{
			get { return searchjobid; }
			set 
            { 
                this.searchjobid = value;
                for (int i = 0; i < this.searchlocations.Count; i++)
                {
                    this.searchlocations[i].Searchjobid = value;
                }
            }
		}

        public string Name
		{
			get { return name; }
			set { this.name = value; }
		}

		public string Allcriteria
		{
			get { return allcriteria; }
			set { this.allcriteria = value; }
		}

		public byte? Type
		{
			get { return type; }
			set { this.type = value; }
		}

        public List<Searchlocation> Searchlocations
        {
            get { return searchlocations.InnerList; }
        }

        public DateTime? Starttime
        {
            get { return starttime; }
            set { this.starttime = value; }
        }

        public DateTime? Endtime
        {
            get { return endtime; }
            set { this.endtime = value; }
        }

        public long? Totalfiles
        {
            get { return totalfiles; }
            set { this.totalfiles = value; }
        }

        public long? TotalLength
        {
            get { return totalLength; }
            set 
            { 
                totalLength = value;
                if (value != null)
                {
                    gbLength = (float)this.totalLength / 1073741824;
                }
            }
        }

        public string TotalLengthGB
        {
            get 
            {
                return String.Format("{0} GB", this.gbLength.ToString("0.00", MyCi.NumberFormat));
            }
        }

        public SearchFileCollection Files
        {
            get { return files; }
            set { files = value; }
        }

        public Searchjob()
        {
            this.searchlocations = new SearchLocationCollection();
            this.files = new SearchFileCollection();
        } 
	}
}
